package pairwise_model;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class pairwise_mesh {
	private HashMap<String,Integer> stop_mesh = new HashMap<String,Integer>();
	
	public pairwise_mesh(String filename){
		Build_Stop_Mesh(filename);
	}
	public void Build_Stop_Mesh(String filename){
		File f= new File(filename);
		FileInputStream fis;
		try {
			fis = new FileInputStream(f);
			InputStreamReader isr=new InputStreamReader(fis);
			BufferedReader br=new BufferedReader(isr);
			String line = br.readLine();
			while(line != null){
				line = line.trim();
				if(line.length()>0){
					if(!stop_mesh.containsKey(line))
						stop_mesh.put(line, stop_mesh.size());
				}
				line = br.readLine();
			}
			br.close();
		}catch(IOException e){
			e.printStackTrace();
		}
	}
	public int CountCommon(List<String> meshs1, List<String> meshs2){
		int score = 0;
		if(meshs1 == null || meshs2 == null || meshs1.size() ==0 || meshs2.size() ==0)
			return score;
		HashMap<String,Integer> mesh_hash1 = new HashMap<String,Integer>();
		for(String mesh: meshs1){
			if(!stop_mesh.containsKey(mesh))
				mesh_hash1.put(mesh, mesh_hash1.size());
		}
		for(String mesh: meshs2){
			if(mesh_hash1.containsKey(mesh))
				score++;
		}
		return score;
	}
}
